<template>
  <div class="customer-satisfaction">
    <div class="customer-satisfaction__select">
      <div class="customer-satisfaction__select-date">
       <el-select v-model="dataQuarterStr" size="mini" @change="getData">
          <el-option
            v-for="item in dateList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
            >
          </el-option>
        </el-select>
      </div>
    </div>
    <div class="order-summary__content">
      <ve-histogram :data="chartData" :settings="chartSettings" :extend="chartExtend" width="95%" height="15rem" :colors="colors"></ve-histogram>
    </div>
  </div>
</template>
<script>
import { Select, Option } from 'element-ui'
import Histogram from 'v-charts/lib/histogram.common'
import { getKhmyd } from 'src/api/api'
import storage from 'good-storage'
import { formatFontSize } from 'js/utils'
export default {
  components: {
    [Select.name]: Select,
    [Option.name]: Option,
    [Histogram.name]: Histogram,
  },
  data(){
    this.colors = ['#0E962A', '#E56F82']
    return {
      dateList: [
        {
          value: '2016_0',
          label: '2016年1-6月'
        },
        {
          value: '2016_1',
          label: '2016年7-12月'
        },
        {
          value: '2017_0',
          label: '2017年1-6月'
        },
        {
          value: '2017_1',
          label: '2017年7-12月'
        },
        {
          value: '2018_0',
          label: '2018年1-6月'
        },
        {
          value: '2018_1',
          label: '2018年7-12月'
        },
        {
          value: '2019_0',
          label: '2019年1-6月'
        },
        {
          value: '2019_1',
          label: '2019年7-12月'
        },
        {
          value: '2020_0',
          label: '2020年1-6月'
        },
        {
          value: '2020_1',
          label: '2020年7-12月'
        },
      ],
      dataQuarterStr: '2020_0',
      chartData: {
        columns: ['cityName', 'khmyd','citymyd'],
        rows: []
      },
      chartSettings: {
        showLine: ['citymyd'],
        labelMap: {
          'khmyd': '满意度',
          'citymyd': '满意度达标线'
        },
      },
      chartExtend: {
        title: {
          text: '各城市客户满意度显示图',
          textStyle: {
            color: '#fff',
            fontSize: formatFontSize(0.12),
          },
          right: 0,
          top: '3%'
        },
        legend: {
          show: true,
          textStyle: {
            color: '#fff',
            fontSize: formatFontSize(0.12),
          },
          selectedMode: false,
          left: '10%',
          top: '5%',
          itemWidth: formatFontSize(0.13),
          itemHeight: formatFontSize(0.08),
        },
        xAxis: {
          axisLabel: {
            color: '#fff',
            // fontSize: 10,
          },
        },
        yAxis: {
          axisLabel: {
            formatter: '{value}%',
            color: '#fff',
            fontSize: formatFontSize(0.1),
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: '#fff',
              opacity: 0.1,
            }
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: '#fff',
              opacity: 0.1,
            }
          },
          max: 100,
          splitNumber: 10,
        },
        grid: {  
          left: '0',  
          right: '0',
          top: '25%',
          bottom: '0',  
        },
        series: {
          barWidth: formatFontSize(0.2),
          label: { 
            show: true, 
            position: 'top',
            color: '#fff',
            fontSize: formatFontSize(0.1),
            // formatter: '{c}%',
            formatter: param => {
              let target = ''
              if(param.seriesType == 'bar') {
                target = param.data + '%'
              }else if(param.seriesType == 'line') {
                target = ''
              }
              return target
            }
          },
        }
      },
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    getData() {
      const params = {
        dataQuarterStr: this.dataQuarterStr
      }
      getKhmyd(params).then(res=> {
        this.chartData.rows = res.data
      })
    }
  }
}
</script>
<style lang="scss">
.customer-satisfaction {
  &__select {
    text-align: right;
    padding: 5px 10px 5px 0;
    font-size: 14px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    color: #AAECFF;
    .el-select {
      .el-input__inner {
        // width: 150px;
        border: 0;
        border-radius: 0;
        background:rgba(11,21,58,1);
        box-shadow:1px 1px 0px 0px rgba(255,255,255,0.25), 0px 2px 4px 0px rgba(0, 0, 0, 1);
        color: #AAECFF;
        font-size: 14px;
      }
      .el-input__icon {
        color: #AAECFF;
        font-size: 14px;
      }
    }
    &-date {
      margin-right: 20px;
      .el-select {
        width: 150px;
      }
    }
  }
  &__table {
    display: flex;
    justify-content: center;
    table {
      td {
        border: 1px solid #6A97AA;
        width: 40px;
        height: 18px;
        font-size: 10px;
        color: #6A97AA;
        text-align: center;
        vertical-align: middle;
      }
      .column {
        td {
          font-size: 9px;
        }
      }
      .title {
        width: 50px;
      }
    }
  }
}
</style>